#include "AppDelegate.h"

#include "cocos2d.h"
#include "HelloWorldScene.h"
#include "mainwindow.h"
#include "CCEGLView.h"
#include "constantManager.h"
#include "QtGui"
USING_NS_CC;

#if (CC_TARGET_PLATFORM == CC_PLATFORM_QT)
AppDelegate::AppDelegate(int argc, char *argv[]) : CCApplication(argc, argv)
{
}
#else
AppDelegate::AppDelegate() {
}
#endif

AppDelegate::~AppDelegate() {
}



bool AppDelegate::initInstance() {
	bool bRet = false;
do{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_QT)
        CCEGLView * pMainWnd = new CCEGLView();
        CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(480, 320));

//        CC_BREAK_IF(! pMainWnd|| ! pMainWnd->Create(320, 480));
        
        MainWindow *m_qwindow = new MainWindow(pMainWnd , 0 );
        ConstantManager::sharedManager()->setMainWindow(m_qwindow);
        m_qwindow->show();
        
//        QWidget *window = new QWidget();
//        window->setAttribute(Qt::WA_DeleteOnClose);
//        QHBoxLayout *layout = new QHBoxLayout(window);
//        layout->addWidget(pMainWnd->m_widget);
//        window->show(); 
        
        
#endif
		bRet = true;
	} while (0);
	return bRet;
}

bool AppDelegate::applicationDidFinishLaunching() {
	// initialize director
	CCDirector *pDirector = CCDirector::sharedDirector();

	pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());

	// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
//     pDirector->enableRetinaDisplay(true);

	// turn on display FPS
	pDirector->setDisplayFPS(true);

//	pDirector->setDeviceOrientation(CCDeviceOrientationLandscapeLeft);
//    pDirector->setDeviceOrientation(CCDeviceOrientationPortrait);
    

	// set FPS. the default value is 1.0/60 if you don't call this
	pDirector->setAnimationInterval(1.0 / 60);

	// create a scene. it's an autorelease object
	CCScene *pScene = HelloWorld::scene();

	// run
	pDirector->runWithScene(pScene);

	return true;
}

// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground() {
	CCDirector::sharedDirector()->pause();

	// if you use SimpleAudioEngine, it must be pause
	// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}

// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground() {
	CCDirector::sharedDirector()->resume();

	// if you use SimpleAudioEngine, it must resume here
	// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}
 
 